


static func collision(_self, delta):
	var gear_speed = _self.gear_speed;
	var gear_fractionFactor = _self.gear_fractionFactor;
	var areas = _self.get_overlapping_areas();
	_self.collided_gears = [];
	var collided_gears = _self.collided_gears;
	for gear in areas:
		if(gear.is_in_group('gear_group')):
			collided_gears.append(gear)
			do_spd_balance(_self, gear, delta);
			gear.queue_redraw()
			_self.queue_redraw()


static func do_spd_balance(_self, gear, delta):
	var tg_ff = gear.gear_fractionFactor;
	var mg_ff = _self.gear_fractionFactor;
	var ff = tg_ff * mg_ff;
	var target_spd = (_self.gear_speed + (-gear.gear_speed)) / 2;
	_self.gear_speed += (target_spd - _self.gear_speed) * ff * delta;
	var relate_angle = _self.position.angle_to_point(gear.position);
	if(_self.gear_speed > gear.gear_speed):
		if(abs(_self.gear_speed + gear.gear_speed) < 45):
			_self.sprite_obj.rotation = -gear.sprite_obj.rotation + relate_angle * 2 + deg_to_rad(45/2);
		## 挤出
		#var min_dis = get_min_geardis(_self, gear)
		#var cur_dis = _self.position.distance_to(gear.position);
		#if(cur_dis < min_dis):
			#gear.position += Vector2(min_dis - cur_dis, 0).rotated(relate_angle) / 2;
			#_self.position -= Vector2(min_dis - cur_dis, 0).rotated(relate_angle) / 2;
	
	if(abs(_self.gear_speed) > 10 ** 8):
		_self.gear_speed = 10 ** 8;

static func get_min_geardis(g1, g2):
	var sr = g1.gear_radius;
	var gr = g2.gear_radius;
	return sr * 4/5 + gr * 4/5 + max(sr, gr) * 1/5;
	
